<?php
//初始化
include_once('init.php');
include_once('./libs/db.php');

include_once('smarty_init.php');

include_once('./libs/department_service.php');
include_once('./libs/class_service.php');
include_once('./libs/fk_service.php');
include_once("./libs/student_service.php");

//实现跳转页面
if(@$_REQUEST['page'] != ''){

	$type_name = getUserType($_SESSION['user_info']['type_id']);
	$smarty->assign('type_name', $type_name);

	$smarty->assign('user_info', $_SESSION['user_info']);

	switch($_REQUEST['page']){
		case 'top':
			//导航栏
			$smarty->display('top.html');
			break;
		case 'left':
			//左边框
			$smarty->display('left.html');
			break;
		case 'right':
			//右边框
			$smarty->display('right.html');
			break;
		case 'home':
			//公告页面
			$smarty->display('home.html');
			break;
		case 'pwdAlert':
			//修改密码
			$smarty->display('pwdAlert.html');
			break;
		case 'student_input':
			//获取所有的系信息
			$department_ary = getAllDepartment();
			$smarty->assign('department_ary', $department_ary);

			//获取所有的班级信息
			$class_ary = getAllClass();
			$smarty->assign('class_ary', $class_ary);

			//获取政治面貌信息
			$party_ary = getAllPartyType();
			$smarty->assign('party_ary', $party_ary);

			$smarty->display('student_input.html');
			break;
		case 'student_listAll':
			$smarty->display('student_list.html');
			break;
		case 'search_student':
			//获取所有的系信息
			$department_ary = getAllDepartment();
			$smarty->assign('department_ary', $department_ary);

			//获取所有的班级信息
			$class_ary = getAllClass();
			$smarty->assign('class_ary', $class_ary);

			//获取政治面貌信息
			$party_ary = getAllPartyType();
			$smarty->assign('party_ary', $party_ary);

			//search_student();
			search_student($smarty);
			break;
		case 'upload':
			$smarty->assign("act", $_REQUEST['act']);
			$smarty->display("upload.html");
	}
}



//通过用户类型id，获取用户类型名称
function getUserType($typeId){
	$sql = "SELECT type_name from _user_type where type_id = $typeId";

	$result = queryStr($sql);

	return $result['rows'][0]['type_name'];
}


//search_student,通过id查询出该学生信息
function search_student(&$smarty){
	$id = '';

	if($_REQUEST['id'] != ''){
		$id = $_REQUEST['id'];

		$result = getStudnetById($id);

		if($result != ''){
			if($result['birthday'] != ''){
				$result['birthday'] = date("Y-m-d", $result['birthday']);
			}
			
			if($result['enrolTime'] != ''){
				$result['enrolTime'] = date("Y-m-d", $result['enrolTime']);
			}
			
			$smarty->assign('student_info', $result);
			$smarty->display('student_show.html');
			
		}else{
			echo "<script>alert('输入的ID有误，查询失败')</script>";
			echo "<script>history.go(-1)</script>";
		}
	}
}

//search_student

?>